package com.example.icedcap.topeka_fake.model.quiz;

import android.os.Parcel;

import com.example.icedcap.topeka_fake.helper.AnswerHelper;

/**
 * Author: doushuqi
 * Date: 15/7/15
 * Time: 上午11:29
 * Email: shuqi.dou@singuloid.com
 */
public final class ToggleTranslateQuiz extends OptionQuiz<String[]> {
    private String[] mReadableOption;

    public ToggleTranslateQuiz(String question, int[] answer, String[][] options, boolean solved) {
        super(question, answer, options, solved);
    }

    @SuppressWarnings("unused")
    protected ToggleTranslateQuiz(Parcel in) {
        super(in);
        setAnswer(in.createIntArray());
        setOptions((String[][]) in.readSerializable());
    }

    @Override
    public QuizType getQuizType() {
        return QuizType.TOGGLE_TRANSLATE;
    }

    @Override
    public String getStringAnswer() {
        return AnswerHelper.getAnswer(getAnswer(), getReadableOption());
    }

    public String[] getReadableOption() {
        if (null == mReadableOption) {
            final String[][] options = getOptions();
            mReadableOption = new String[options.length];
            for (int i = 0; i < options.length; i++) {
                mReadableOption[i] = createReadablePair(mReadableOption);
            }

        }
        return mReadableOption;
    }

    private String createReadablePair(String[] option) {
        return option[0] + " <> " + option[1];
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
    }

}
